summaryrefslogtreecommitdiff
path: root/src/frontend/pages/api/products/[productId]
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/pages/api/products/[productId]')
-rw-r--r--src/frontend/pages/api/products/[productId]/index.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/frontend/pages/api/products/[productId]/index.ts b/src/frontend/pages/api/products/[productId]/index.ts
new file mode 100644
index 0000000..eb62465
--- /dev/null
+++ b/src/frontend/pages/api/products/[productId]/index.ts
@@ -0,0 +1,26 @@
+// Copyright The OpenTelemetry Authors
+// SPDX-License-Identifier: Apache-2.0
+
+import type { NextApiRequest, NextApiResponse } from 'next';
+import InstrumentationMiddleware from '../../../../utils/telemetry/InstrumentationMiddleware';
+import { Empty, Product } from '../../../../protos/demo';
+import ProductCatalogService from '../../../../services/ProductCatalog.service';
+
+type TResponse = Product | Empty;
+
+const handler = async ({ method, query }: NextApiRequest, res: NextApiResponse<TResponse>) => {
+ switch (method) {
+ case 'GET': {
+ const { productId = '', currencyCode = '' } = query;
+ const product = await ProductCatalogService.getProduct(productId as string, currencyCode as string);
+
+ return res.status(200).json(product);
+ }
+
+ default: {
+ return res.status(405).send('');
+ }
+ }
+};
+
+export default InstrumentationMiddleware(handler);